<%-- 
    Document   : AltaUsuario
    Created on : 28-feb-2012, 17:43:40
    Author     : sup3rm4r10
--%>

<%@page import="java.util.Iterator"%>
<%@page import="java.util.Set"%>
<%@page import="ipostservices.services.UserSrv"%>
<%@page import="ipostservices.model.bean.User"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@page import="ipostservices.model.bean.Project"%>
<%@page import="ipostservices.services.ProjectSrv"%>
<%@page import="java.util.List"%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" type="text/css" href="Estilos/misEstilos.css">
        <title>Perfil de Usuario</title>
        
        <script type="text/javascript">
            function modificar()
            {
                
                document.getElementById("guardar").style.display="block";
                document.getElementById("opciones").style.display="none";
                document.getElementById("iduser").disabled=false;
                document.getElementById("username").disabled=false;
                document.getElementById("email").disabled=false;
                document.getElementById("pass").disabled=false;
                }
                
                function eliminar(iduser)
            {
                if(confirm("Seguro desea eliminar este usuario??")){
                    window.location ="BajaUsuario?idUsuario="+iduser;
                    
                }
                
                }
                
                function setChecked(id){
                
                var check = document.getElementById(id);
                check.checked=true;
                }

            
</script>


        <script type="text/javascript">
var EvRegister=[]; 
var panino=(function(){
/* ---- métodos privados ---- */
	var metodosPrivados={
		addEvent: function(type, fn ) {
			if ( this.addEventListener ) {
				this.addEventListener( type, fn, false );
			} else if(this.attachEvent){
				var _this=this;
				var f= function(){fn.call(_this,window.event);}
				this.attachEvent( 'on'+type, f);
				this[fn.toString()+type]=f;
			}else{
				this['on'+type]=fn;
			}
			var ev={_obj:this,_evType:type,_fn:fn};
    		window.EvRegister.push(ev);
			return this;
		},
		removeEvent: function(type, fn ) {
			if( this.removeEventListener){
				this.removeEventListener( type, fn, false );
			}
    		else if(this.detachEvent){
				this.detachEvent('on'+type,this[fn.toString()+type]);
				this[fn.toString()+type]=null;
			}
			else{
	 	 		this['on'+type]=function(){};
			}
			for (var ii= 0, l=window.EvRegister.length; ii < l ; ii++) {
        		if (window.EvRegister[ii]._evType== type && window.EvRegister[ii]._obj==this && window.EvRegister[ii]._fn==fn) {
            		window.EvRegister.splice(ii, 1);
            		break;
					
        		}
    		} 
    		return this;
   		 },
		 css:function(propiedad,valor){
		 	if(!valor)
				return this.style[propiedad];
			this.style[propiedad]=valor;
			return this;
		 },
		 hover:function(a,b){
		 	this.addEvent('mouseover', a );
			this.addEvent('mouseout', b );
			return this;
		 },
		 alfa:function(value){
			this.style.opacity = value;
    		this.style.MozOpacity = value;
    		this.style.KhtmlOpacity = value;
    		this.style.filter = 'alpha(opacity=' + value*100 + ')';
    		this.style.zoom=1;
			return this;
		},
		toggle:function(a,b){
			this.style.display=this.style.display=='none'?'block':'none';
			if(!!a && !!b)
				a.parentNode.replaceChild(b,a);
			return this;
		},
		extendido:true
		 
	}
/* ---- métodos públicos ---- */
	return{
		extend:function(el,obj){
			if(el.extendido && el!=metodosPrivados)return el;
			for(var i in obj)
				el[i]=obj[i];
			return el;
		},
		get:function(id){
			if(!document.getElementById(id))return false;
			return panino.extend(document.getElementById(id),metodosPrivados);
		},
		getO:function(obj){
			return panino.extend(obj,metodosPrivados);
		},
		add:function(obj){
			panino.extend(metodosPrivados,obj);
		}
	}	
})();
function unregisterAllEvents() {
    while (EvRegister.length > 0) {
        panino.getO(EvRegister[0]._obj).removeEvent(EvRegister[0]._evType,EvRegister[0]._fn);
    }
}
var $=panino.get;
panino.getO(window).addEvent('unload',unregisterAllEvents);

function Acordeon(id,abierto){
	this.abierto=abierto || 0;
	this.id=id;
	this.init=function(){
		var _this=this;
		for(var i=0,els; els=$(this.id).getElementsByTagName('dt')[i];i++){
			var maxExpand=$(this.id).getElementsByTagName('dd')[i].offsetHeight;
			if(!this.abierto || this.abierto!=i+1){
				$(this.id).getElementsByTagName('dd')[i].style.height=0;
				$(this.id).getElementsByTagName('dd')[i].style.display='none';
				$(this.id).getElementsByTagName('dd')[i].creciendo=1;
			}else{
				$(this.id).getElementsByTagName('dd')[i].creciendo=0;
				$(this.id).getElementsByTagName('dd')[i].style.height=maxExpand+'px';
			}
			
			(function(){
				var _maxExpand=maxExpand;
				var numero=i;
				panino.getO(els).addEvent('click',function(){_this.efectuar(_maxExpand,numero);}).css('cursor','pointer');
				panino.getO(window).addEvent('unload',function(){$(_this.id).getElementsByTagName('dd')[numero].t=null;$(_this.id).getElementsByTagName('dd')[numero].creciendo=null;});
			})()
		}
		$(this.id).css('visibility','visible');
	}
	this.efectuar=function(maximo,elemento){
		var _this=this;
		if($(_this.id).getElementsByTagName('dd')[elemento].t!=null && typeof $(_this.id).getElementsByTagName('dd')[elemento].t!='undefined' && $(_this.id).getElementsByTagName('dd')[elemento].t.done_!=true)return;
		var inicio=parseInt($(this.id).getElementsByTagName('dd')[elemento].style.height);
		var fin= $(_this.id).getElementsByTagName('dd')[elemento].creciendo ? maximo  : 0; 
		$(_this.id).getElementsByTagName('dd')[elemento].creciendo=!$(_this.id).getElementsByTagName('dd')[elemento].creciendo;
		$(_this.id).getElementsByTagName('dd')[elemento].t=new Transition(SineCurve, 500, function(percentage) {
			if(fin<inicio){
				var delta=inicio-fin;
    			$(_this.id).getElementsByTagName('dd')[elemento].style.height=(inicio-(percentage*delta))+'px';
			}
			else{
				var delta=fin-inicio;
				$(_this.id).getElementsByTagName('dd')[elemento].style.height=(inicio+(percentage*delta))+'px';
			}
			if(parseInt($(_this.id).getElementsByTagName('dd')[elemento].style.height)<1)
				$(_this.id).getElementsByTagName('dd')[elemento].style.display='none';
			else
				$(_this.id).getElementsByTagName('dd')[elemento].style.display='block';
			});
		$(_this.id).getElementsByTagName('dd')[elemento].t.run();
	}
	
}
function Transition(curve, milliseconds, callback) {
		this.done_=false;
    	this.curve_ = curve;
    	this.milliseconds_ = milliseconds;
    	this.callback_ = callback;
    	this.start_ = new Date().getTime();
		this.run=function() {
			var _this=this;
   			if(!this.hasNext()) {
				window['globalIntervalo']=0;
				return;
			}
    		this.callback_(this.next());
			setTimeout(function(){_this.run.call(_this);}, 0);
		}
		this.hasNext=function() {
    		if(this.done_)
				return false;
    		var now = new Date().getTime();
    		if ((now - this.start_) > this.milliseconds_) {
       			this.done_ = true;
    		}
    		return true;
		}
		this.next=function() {
    		var now = new Date().getTime();
    		var percentage = Math.min(1, (now - this.start_) / this.milliseconds_);
			return this.curve_(percentage);
		}
}

function SineCurve(percentage) {
	return (1 - Math.cos(percentage * Math.PI)) / 2;
}
onload=function(){
var t=new Acordeon('lista');
t.init();
}
</script>
    </head>
    
    
    
    
    
    
    
    
    
    <body>
        <div id="cuerpo"></div>
        <div id="imagenpost"><a href="index.jsp"> <img src="Imagenes/Icono_IPost_icono.png" alt="login" /></a>   </div>
        <div id="imagenpostit"> <img src="Imagenes/registro.png" alt="registro" />  </div>
        
<article>

    <section id="Title">
<h2 style="font-family:Arial, Helvetica, sans-serif; font-size:20px">Perfil de Usuario</h2>
 

 <section id="Form">
               
     <%
        User user = null;
        user = (User)request.getSession().getAttribute("user");        
     %>
     
     
     
     <form action="ModificarUsuario" method="post" >
         <div contentEditable="true">
                    <table style="position:absolute; left:30px; top:20px" >
                        <tr>
                            <td width="297">
                                <%
                    out.println("Id:</br> <input id='iduser' type='text'  size='5' name='idusuario'  readonly='readonly' value='"+ user.getIduser()+"'>");
                            %>              
                            </td>   
                            
                        </tr>
                        
                        <tr> 
                            <td width="297">
                                <%
                                out.println("Nombre de usuario:</br> <input id='username' type='text'  size='30' name='usuario' autofocus value='"+ user.getUsername()+"'/>");
                                        %>
                            </td>                                                              
                        </tr>
                        
                        <tr>
                            <td>
                                <%
                                out.println("Email:</br> <input id='email' type='email'  size='30' name='mail'  value='"+ user.getEmail()+"'/>");
                                        %>
                            </td>
                            <td width="21"><pre></pre></td>
                        </tr>
                        
                        
                        <tr>
                            <td>
                                <%
                                out.println("Contraseña:</br> <input id='pass' type='text' size='30' name='password' value='"+ user.getPassword()+"' />");
                                        %>
                            </td>
                            
                        </tr>
                        
                        <%--        <tr>&nbsp;</tr><tr>&nbsp;</tr><tr>&nbsp;</tr><tr>&nbsp;</tr>   --%>
                        
                        <tr>
                            <td>
                                <input id="guardar" type="submit" value="Guardar" style="display:none"/>
                            
                                <div id="opciones">
                                    <img src="Imagenes/lapizIcon.png" onclick="modificar()" title="Modificar Datos de Usuario" style="cursor: pointer"/>
                                    <%
                                    out.println("<img  src='Imagenes/eliminar.png' onclick='eliminar("+ user.getIduser()  +")' title='Eliminar Usuario' style='cursor: pointer' />");
                                            %>
                                </div>
                            </td>
                        </tr>
                        </table>
        
         <div id="combo">
         <%
            ProjectSrv proyecto = new ProjectSrv();
            List <Project> proyectos = proyecto.getProys();
            
            UserSrv userService = new UserSrv();
            User userTemp =  userService.getUser(user.getIduser());
            Set <Project> proyects = userTemp.getProjects_1();
           // List <Project> userproys = proyecto.getProysUser(user.getIduser());
            
            out.println("<tr> ");
            out.println("<td> ");
            out.println("<dl id='lista'>");
            out.println("<dt>Proyectos<div id='flecha'></div></dt>");
            out.println("<dd>");
            
            for(int i=0;i<proyectos.size();i++){
                out.println("<input id='checkbox"+proyectos.get(i).getIdproject()+"' name='proy' type='checkbox' value='"+proyectos.get(i).getIdproject()+"' style='cursor: pointer' />"+ proyectos.get(i).getTitulo() +"<br/>");             
                 
                Project proyect = new Project();
            Iterator<Project> it = proyects.iterator();
            int j=0;
            while ( it.hasNext()) {
                proyect = it.next();
                     if(proyectos.get(i).getIdproject().equals(proyect.getIdproject())) {
                       out.println("<script>setChecked('checkbox"+proyectos.get(i).getIdproject()+"'); </script>");
                         break;
                     }
            }
                
                
                
            }
            out.println("</dd>");
            out.println("</dl>");
            
            out.println("</td> ");
            out.println(" </tr> ");
            
           


%>
         </div>
         </div>
         
     </form>
 </section>
         
    </section>
</article>
        
        <footer id="pie">
            
            copyRight <br> Mario cortes &copy;
            
        </footer>
</body>
</html>
